#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_excipolar2.info <<'%EOF%'
   rsp_excipolar2
   --------------
   Molecule:         LiH
   Wave Function:    MCSCF (CAS) / 4-31G
   Test Purpose:     Polarizability of an excited state
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_excipolar2.mol <<'%EOF%'
BASIS
4-31G
Calculation of the polarizability of an excited state

    2    2  X  Y    1 1.00D-12
        1.0   1
H           .0000000000             .0000000000            2.0969699107
        3.0   1
Li          .0000000000             .0000000000            -.9969699107
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_excipolar2.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONS
**WAVE FUNCTIONS
.HF
.MP2
.MCSCF
*SCF INPUT
.DOUBLY OCCUPIED
 2 0 0 0
*CONFIGURATION INPUT
.INACTIVE
 1 0 0 0
.ELECTRONS
 2
.CAS SPACE
 2 0 0 0
.SYMMET
 1
.SPIN MULT
 1
**RESPONS
*CUBIC
.DIPLEN
.DOUBLE
.ROOTS
 2 1 0 0
.FREQUE
 1
0.03
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_excipolar2.check
cat >>rsp_excipolar2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Basis set
CRIT1=`$GREP "H * 1 * 1\.0000 * 4 * 2 * \[4s\|2s\]" $log | wc -l`
CRIT2=`$GREP "Li * 1 * 3\.0000 * 17 * 9 * \[8s3p\|3s2p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 2 * 4\.0000 * 21 * 11" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=3
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 6" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * 2\.0969699107" $log | wc -l`
CRIT5=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT7=`$GREP "6 * z * (\-0|\-)\.9969699107" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7`
CTRL[2]=7
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 2 * 2 * 2 * 0" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 7 * 2 * 2 * 0" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="SYMMETRY NOT CORRECT"

# Energies
CRIT1=`$GREP "Hartree\-Fock total energy *\: * \-7\.9773493(6|7).." $log | wc -l`
CRIT2=`$GREP "\= MP2 second order energy *\: * \-7\.9901927.." $log | wc -l`
CRIT3=`$GREP "Final MCSCF energy\: * \-7\.9941305(2|3)...." $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[4]=3
ERROR[4]="ENERGIES NOT CORRECT"

# Response setup
CRIT1=`$GREP "Cubic response two\-photon absorption TPAMP\=T" $log | wc -l`
CRIT2=`$GREP "Excited state polarizability requested TPALP\=T" $log | wc -l`
CRIT3=`$GREP "1 B\-frequencies * 3\.000000(D|E)\-02" $log | wc -l`
CRIT4=`$GREP "1 A OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
CRIT5=`$GREP "1 B OPERATORS OF SYMMETRY NO\: * [1-3] AND LABELS\:" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[5]=9
ERROR[5]="RESPONSE CALCULATION NOT SET UP CORRECTLY"

# Polarizability (ZDIPLEN - Sym 1, State 1 - Sym 1)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 263\.5.* 263\.5" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-185\.5.* 77\.9" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * \-33\.53.* 44\.3" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * \-25\.02.* 19\.3" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-19\.9.* (\-0|\-)\.5" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * 15\..* 14\.8" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 1 * 1 * 0*\.11958" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * 14\.8" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[6]=13
ERROR[6]="EXCITED STATE POLARIZABILITY (ZDIPLEN - SYM 1, STATE 1 - SYM 1) NOT CORRECT"

# Polarizability (ZDIPLEN - Sym 1, State 2 - Sym 1)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 137\.4.* * 137\.4" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-121\.4.* * 16\.0" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 27\.8.* * 43\.8" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 34\.7.* * 78\.6" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-18\.2.* * 60\.3" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-154\.5.* * \-94\.[12]" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 2 * 1 * 0*\.27218" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * \-94\.[12]" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[7]=13
ERROR[7]="EXCITED STATE POLARIZABILITY (ZDIPLEN - SYM 1, STATE 2 - SYM 1) NOT CORRECT"

# Polarizability (XDIPLEN - Sym 2, State 1 - Sym 1)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 100\.4.* 100\.4" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-21\.7.* 78\.7" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 13\.4.* 92\.1" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 26\.9.* 119\.1" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-44\.5.* 74\.6" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-372\.9.* \-298\.3" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 1 * 1 * 0*\.11958" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * \-298\.3" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[8]=20
ERROR[8]="EXCITED STATE POLARIZABILITY (XDIPLEN - SYM 2, STATE 1 - SYM 1) NOT CORRECT"

# Polarizability (XDIPLEN - Sym 2, State 2 - Sym 1)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 64\.4.* 64\.4" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-24\.4.* 40\.0" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 15\.7.* 55\.8" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 27\.5.* 83\.3" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-36\.4.* 46\.8" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-51\.[78].* \-4\.9" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 2 * 1 * 0*\.27218" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * \-4\.9" $log | wc -l`
TEST[9]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[9]=20
ERROR[9]="EXCITED STATE POLARIZABILITY (XDIPLEN - SYM 2, STATE 2 - SYM 1) NOT CORRECT"

# Polarizability (YDIPLEN - Sym 3, State 1 - Sym 1)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 100\.4.* 100\.4" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-21\.7.* 78\.7" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 13\.4.* 92\.1" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 26\.9.* 119\.1" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-44\.5.* 74\.6" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-372\.9.* \-298\.3" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 1 * 1 * 0*\.11958" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * \-298\.3" $log | wc -l`
TEST[10]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[10]=20
ERROR[10]="EXCITED STATE POLARIZABILITY (YDIPLEN - SYM 3, STATE 1 - SYM 1) NOT CORRECT"

# Polarizability (YDIPLEN - Sym 3, State 2 - Sym 1)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 64\.4.* 64\.4" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-24\.4.* 40\.0" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 15\.7.* 55\.8" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 27\.5.* 83\.3" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-36\.4.* 46\.8" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-51\.[78].* \-4\.9" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 2 * 1 * 0*\.27218" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * \-4\.9" $log | wc -l`
TEST[11]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[11]=20
ERROR[11]="EXCITED STATE POLARIZABILITY (YDIPLEN - SYM 3, STATE 2 - SYM 1) NOT CORRECT"

# Polarizability (ZDIPLEN - Sym 1, State 1 - Sym 2)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 107\.6.* 107\.6" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-66\.9.* 40\.6" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 1\.0.* 41\.7" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 10\.1.* 51\.9" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-29\.1.* 22\.7" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-8\.[89].* 13\.8" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 1 * 2 * 0*\.15776" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * 13\.8" $log | wc -l`
TEST[12]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[12]=13
ERROR[12]="EXCITED STATE POLARIZABILITY (ZDIPLEN - SYM 1, STATE 1 - SYM 2) NOT CORRECT"

# Polarizability (XDIPLEN - Sym 2, State 1 - Sym 2)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 239\.4.* 239\.4" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-225\.1.* 14\.3" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 90\.8.* 105\.1" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 112\.1.* 217\.2" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-57\.2.* 159\.9" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * 174\..* 334\." $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 1 * 2 * 0*\.15776" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * 334\." $log | wc -l`
TEST[13]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[13]=13
ERROR[13]="EXCITED STATE POLARIZABILITY (XDIPLEN - SYM 2, STATE 1 - SYM 2) NOT CORRECT"

# Polarizability (YDIPLEN - Sym 3, State 1 - Sym 2)
CRIT1=`$GREP "Na T\[4\] Nb Nc Nd * 117\.5.* 117\.5" $log | wc -l`
CRIT2=`$GREP "Na T\[3\] Nx Nyz * \-65\.0.* 52\.4" $log | wc -l`
CRIT3=`$GREP "Na X\[3\] Ny Nz * 36\.7.* 89\.1" $log | wc -l`
CRIT4=`$GREP "Nx A\[3\] Ny Nz * 53\.7.* 142\.9" $log | wc -l`
CRIT5=`$GREP "Na X\[2\] Nyz * \-57\.2.* 85\.6" $log | wc -l`
CRIT6=`$GREP "Nx A\[2\] Nyz * \-57\.2.* 28\.3" $log | wc -l`
CRIT7=`$GREP "\@ State no\.\, symmetry\, excitation energy\: * 1 * 2 * 0*\.15776" $log | wc -l`
CRIT8=`$GREP "\@ < e \| AB \| f > * \= * 28\.3" $log | wc -l`
TEST[14]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8`
CTRL[14]=13
ERROR[14]="EXCITED STATE POLARIZABILITY (YDIPLEN - SYM 3, STATE 1 - SYM 2) NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
